package com.yangming.controller;

import com.yangming.common.base.BaseController;
import com.yangming.common.base.BaseResponseEnum;
import com.yangming.common.utils.BackJsonBeanUtil;
import com.yangming.model.User;
import com.yangming.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户Controller
 * @author PengShuiMing
 * @create 2018-09-07
 **/
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
    private static final Logger logger =   LoggerFactory.getLogger(UserController.class);
    @Autowired
    private IUserService userService;

    /**
     *新增用户
     */
    @RequestMapping("/saveUser.json")
    public Object saveUser(User user) {
        //返回信息
        BaseResponseEnum responseEnum = BaseResponseEnum.ERROR;
        try {
            int result = userService.saveUser(user);
            if(result>0){
                responseEnum = BaseResponseEnum.SUCCESS;
            }
        } catch (Exception e) {
            logger.error("[新增用户]",e.getMessage(),e);
        }
        return BackJsonBeanUtil.getBackJsonBean(responseEnum,null);
    }


}
